package cc.vv.btpartyjob.partymanager.activity

import android.view.View
import cc.vv.baselibrary.bean.base.BaseResponseObj
import cc.vv.baselibrary.view.BaseTopBarView
import cc.vv.btpartyjob.jnimodule.enums.H5UrlEnum
import cc.vv.btpartyjob.jnimodule.server.JniStartActivity
import cc.vv.btpartyjob.partymanager.delegate.ManagerBaseBinder
import cc.vv.btpartyjob.partymanager.delegate.QiShiYeDanWeiActivityDelegate
import cc.vv.btpartyjob.partymanager.moudel.resp.GridListResponseObj
import cc.vv.btpartyjob.partymanager.server.PartyManagerServer
import cc.vv.mvp.activity.BaseActivityMVP
import cc.vv.mvp.binder.BaseDataBinder
import cc.vv.party.beans.vo.OrgVO
import com.chad.library.adapter.base.BaseQuickAdapter

/**
 * 企事业单位列表
 * Created by Chen.qi on 2018/10/25.
 */
class QiShiYeDanWeiActivity : BaseActivityMVP<QiShiYeDanWeiActivityDelegate>(), BaseQuickAdapter.OnItemClickListener {

    /**
     * 社区ID
     */
    private var communityId: String? = null

    /**
     * 数据
     */
    private var mDataList: ArrayList<OrgVO>? = null

    override fun initData() {
        viewDelegate?.setTopBarTitle("单位")
        mDataList = ArrayList()
        try {
            communityId = intent.getStringExtra("communityId")
            PartyManagerServer.getUnitList(communityId + "", true)
        } catch (e: Exception) {
        }
    }

    override fun bindEvenListener() {
        viewDelegate?.setTitleBackBtnOnClick(object : BaseTopBarView.EventInterface {
            //返回
            override fun leftOnClick() {
                finish()
            }

            override fun leftCloseClick() {}
            override fun rightOnClick() {
            }
        })
        viewDelegate.bindOnItemClick(this)

    }

    override fun getDelegateClass(): Class<QiShiYeDanWeiActivityDelegate> {
        return QiShiYeDanWeiActivityDelegate::class.java
    }

    override fun getDataBinder(): BaseDataBinder<*, *> {
        return ManagerBaseBinder()
    }

    override fun onItemClick(adapter: BaseQuickAdapter<*, *>?, view: View?, position: Int) {
        //单位详情
        JniStartActivity.startIntentWebActivity(this, H5UrlEnum.企事业单位, mDataList!![position].id)
    }

    override fun getData(obj: BaseResponseObj<*>?) {
        super.getData(obj)
        when (obj) {
            is GridListResponseObj -> {
                val data = obj.data
                if (null != data) {
                    mDataList!!.addAll(data)
                }
                viewDelegate.setAdapterData(mDataList)
            }
        }
    }

    override fun getBadCode(obj: BaseResponseObj<*>?) {
        super.getBadCode(obj)
        viewDelegate.setAdapterData(null)
    }

    override fun onHttpFailure(url: String?, exceptionStr: String?) {
        super.onHttpFailure(url, exceptionStr)
        viewDelegate.setAdapterData(null)
    }


}